home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-18 | 2.1 KB | 93 lines | [TEXT/IGR0] |
- | <Keyword-Value>
- |
- | parses "key:value;key2:value2;" list
- | Returns the string value string given the corresponding key
- |
- Function/S StrByKey(key,str)
- String key,str
-
- key += ":"
- Variable pos= strsearch(str, key, 0)
- if( pos < 0 )
- return ""
- endif
- pos += strlen(key)
- Variable pos2= strsearch(str,";",pos)
- if (pos2 == -1) | this is the last value in list ?
- pos2 = strlen(str)
- endif
- return str[pos,pos2-1]
- End
-
- | parses "key:value;key2:value2;" list
- | Returns the numeric value of the string given the corresponding key, or NaN
- |
- Function/D NumByKey(key,str)
- String key,str
-
- String s= StrByKey(key,str)
- if( strlen(s) == 0 )
- return NaN
- endif
- return str2num(s)
- End
-
- | Replaces "<key>:<str>;" in the list, or adds it to the start of the list
- | list is usually a global string containing lots of settings,
- | each setting with a unique key.
- | Note: we ASSUME that key and str do not contain either the ':' or ';' character
- | (if it does, the list is damaged). Any other character, however, is okay.
- | Returns the new list.
- |
- | Usage: listStr= ReplaceStrByKey(listStr,"DayOfWeek","Monday")
- |
- Function/S ReplaceStrByKey(list,key,str)
- String list,key,str
-
- key += ":"
- Variable pos2=0,pos= strsearch(list, key, 0)
- if( pos >= 0 )
- pos += strlen(key)
- pos2= strsearch(list,";",pos)
- list[pos,pos2-1]=str
- else
- list[-1]=key+str+";" | Last-In-First-Out
- endif
- return list
- End
-
- | Replaces "<key>:<value>;" in the list, or adds it to the start of the list
- | See ReplaceStrByKey
- | Returns the new list.
- |
- | Usage: listStr= ReplaceNumByKey(listStr,"angle of attack",3.14159/16)
- |
- Function/S ReplaceNumByKey(list,key,num)
- String list,key
- Variable/D num
-
- String valueAsString
- sprintf valueAsString,"%.15g",num
- return ReplaceStrByKey(list,key,valueAsString)
- End
-
- | Removes "<key>:<str>;" from the list, if it exists.
- | See ReplaceStrByKey
- | Returns the new list.
- |
- | Usage: listStr= DeleteByKey(listStr,"key to delete")
- |
- Function/S DeleteByKey(list,key)
- String list,key
-
- key += ":"
- Variable pos2,pos= strsearch(list, key, 0)
- if( pos >= 0 )
- pos2= strsearch(list,";",pos)
- list[pos,pos2]=""
- endif
- return list
- End
-
-
-